package com.nlp.visualization.core.seg.filter;

import com.nlp.visualization.utils.PropertyUtil;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class CustomDicReader {

    private static Logger logger = LoggerFactory.getLogger(CustomDicReader.class);

    static List<String> stopwordsSet = new ArrayList<>();
    static List<String> punctuationSet = new ArrayList<>();

    static {
        initStopwords();
        initpunctuation();
    }

    private static void initStopwords() {


        logger.info("执行读取停用词表");
        try {
            //读入停用词表
            String stopwordsPath = PropertyUtil.getInstance("library").getProperty("stopWordPath");
            File file = new File(stopwordsPath);
            stopwordsSet = FileUtils.readLines(file, "UTF-8");
        } catch (IOException e) {
            logger.error("读取停用词词库的时候文件异常");
            e.printStackTrace();
        } catch (Exception e) {
            logger.error("读取停用词词库未知异常");
            e.printStackTrace();
        }
        logger.info("完成停用词表加载");


    }

    private static void initpunctuation() {
        logger.info("执行读取标点符号表");
        try {
            //读入标点符号表
            String stopwordsPath = PropertyUtil.getInstance("library").getProperty("punctuationPath");
            File file = new File(stopwordsPath);
            punctuationSet = FileUtils.readLines(file, "UTF-8");
        } catch (IOException e) {
            logger.error("读取标点符号词库的时候文件异常");
            e.printStackTrace();
        } catch (Exception e) {
            logger.error("读取标点符号词库未知异常");
            e.printStackTrace();
        }
        logger.info("完成标点符号表加载");

    }

    public static List<String> readstopwords() {
        return CustomDicReader.stopwordsSet;
    }

    public static List<String> readpunctuation() {
        return CustomDicReader.punctuationSet;
    }

}
